import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class demo1 {
    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> lists=new ArrayList<>();
        Queue<Node>queue=new LinkedList<>();
        if(root==null)return lists;
        queue.add(root);
        while (queue.size()!=0){
            List<Integer> list=new ArrayList<>();
            int n=queue.size();
            while (n!=0){
                Node temp=queue.poll();
                list.add(temp.val);
                for(Node chider: temp.children){
                    if(chider!=null)queue.add(chider);
                }
                n--;
            }
            lists.add(list);
        }
        return lists;
    }

}
